<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateCashbookTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create(
            'cashbook', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('shopId')->default(0)->comment('店铺id');
            $table->unsignedInteger('userId')->default(0)->comment('用户id');
            $table->unsignedInteger('recordTime')->default(0)->comment('记录时间');
            $table->unsignedTinyInteger('type')->default(0)->comment('类型 1-收入 2-支出');
            $table->unsignedTinyInteger('category')->default(0)->comment('分类');
            $table->unsignedTinyInteger('source')->default(0)->comment('来源 1-系统自动同步 2-手动添加 3-周期同步添加');
            $table->integer('amount')->default(0)->comment('金额 单位：分');
            $table->string('remark', 200)->default('')->comment('备注');
            $table->unsignedInteger('cycleId')->default(0)->comment('周期id source=3存在');
            $table->unsignedInteger('orderId')->default(0)->comment('订单id');

            $table->unsignedInteger('isDeleted')->default(0)->comment('是否删除 0 - 正常 1 - 已删除');
            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->collation = 'utf8mb4_general_ci';

            $table->index(['shopId'], 'idx_shopId');
            $table->index(['userId'], 'idx_userId');
            $table->index(['recordTime'], 'idx_recordTime');
            $table->index(['orderId'], 'idx_orderId');
            $table->comment = '记账本';

        }
        );
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cashbook');
    }
}
